package 二分查找;

public class LeetCode1894_找到需要补充粉笔的学生编号 {
    public int chalkReplacer(int[] chalk, int k) {
        long count = 0;
        for(int i = 0; i < chalk.length; i++) {
            count += chalk[i];
        }
        long index = k % count;
        int j = 0;
        while(index > 0) {
            index -= chalk[j];
            if(index <= 0) {
                if(index == 0) {
                    return j+1;
                }
                return j;
            }
            j++;
        }
        return 0;
    }
}
